Fix MBA-471: Resolve High severity string duplication and cognitive complexity issues#69
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
Conversation
…omplexity issues This commit addresses two SonarQube High severity violations: 1. String Duplication (go:S1192): - Created pkg/errors/constants.go with extracted string constants - Updated pkg/errors/error.go to use ErrContextMissingGitHubCtxErrors constant - Replaced 4 instances of duplicated 'context does not contain GitHubCtxErrors' string 2. Cognitive Complexity (go:S3776): - Extracted buildResourceURI helper function for URI construction - Extracted createResourceContent helper function for content type handling - Extracted fetchRawContent helper function for raw content fetching - Refactored GetFileContents handler to use new helpers, reducing nesting levels Co-Authored-By: Jia Wu <jia.wu@cognition.ai>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Closes: MBA-471
Summary
This PR addresses two SonarQube High severity violations identified via SonarQube MCP Server analysis:
String Duplication (go:S1192): Extracted the duplicated error message "context does not contain GitHubCtxErrors" into a constant, replacing 4 instances in
pkg/errors/error.goCognitive Complexity (go:S3776): Refactored
GetFileContentshandler by extracting three helper functions to reduce nesting levelsChanges
pkg/errors/constants.gowith error message constantspkg/errors/error.goto useerrors.New()with the constant (also fixes staticcheck SA1006)pkg/github/repositories.go:buildResourceURI- URI construction logiccreateResourceContent- content type handlingfetchRawContent- raw content fetching logicHuman Review Checklist
fetchRawContent, whenbuildResourceURIfails, the function returns(nil, true)which causes the caller to return(nil, nil). The original code returnedfmt.Errorf("failed to create resource URI: %w", err). Verify this behavior change is acceptable.ErrFailedToGetGitHubClientandErrMissingRequiredParameterare defined but not used - confirm if these should be removed or kept for future use.Tradeoffs
Link to Devin run: https://app.devin.ai/sessions/19a02b2240b04aea803fc007a5cee109
Requested by: Jia Wu (jia.wu@cognition.ai) (@jia-cog)